//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.pentaho.di.ui.spoon.wizards;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.dialogs.ControlEnableState;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.IPageChangeProvider;
import org.eclipse.jface.dialogs.IPageChangedListener;
import org.eclipse.jface.dialogs.IPageChangingListener;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.PageChangedEvent;
import org.eclipse.jface.dialogs.PageChangingEvent;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.operation.ModalContext;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.jface.wizard.*;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.HelpEvent;
import org.eclipse.swt.events.HelpListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.pentaho.di.i18n.BaseMessages;

public class CustomCopyTableWizard extends TitleAreaDialog implements IWizardContainer2, IPageChangeProvider {
    public static final String WIZ_IMG_ERROR = "dialog_title_error_image";
    private static Class<?> PKG = CustomCopyTableWizard.class; // for i18n purposes, needed by Translator2!!

    private IWizard wizard;
    private ArrayList createdWizards = new ArrayList();
    private ArrayList nestedWizards = new ArrayList();
    private IWizardPage currentPage = null;
    private long activeRunningOperations = 0L;
    private String pageMessage;
    private int pageMessageType = 0;
    private String pageDescription;
    private ProgressMonitorPart progressMonitorPart;
    private Cursor waitCursor;
    private Cursor arrowCursor;
    private MessageDialog windowClosingDialog;
    private Button backButton;
    private Button nextButton;
    private Button finishButton;
    private Button cancelButton;
    private Button helpButton;
    private SelectionAdapter cancelListener;
    private boolean isMovingToPreviousPage = false;
    private Composite pageContainer;
    private CustomCopyTableWizard.PageContainerFillLayout pageContainerLayout = new CustomCopyTableWizard.PageContainerFillLayout(5, 5, 300, 225);
    private int pageWidth = -1;
    private int pageHeight = -1;
    private static final String FOCUS_CONTROL = "focusControl";
    private boolean lockedUI = false;
    private ListenerList pageChangedListeners = new ListenerList();
    private ListenerList pageChangingListeners = new ListenerList();

    public CustomCopyTableWizard(Shell parentShell, IWizard newWizard) {
        super(parentShell);
        this.setShellStyle(68720 | getDefaultOrientation());
        this.setWizard(newWizard);
        this.cancelListener = new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                CustomCopyTableWizard.this.cancelPressed();
            }
        };
    }

    private Object aboutToStart(boolean enableCancelButton) {
        Map savedState = null;
        if (this.getShell() != null) {
            Control focusControl = this.getShell().getDisplay().getFocusControl();
            if (focusControl != null && focusControl.getShell() != this.getShell()) {
                focusControl = null;
            }

            boolean needsProgressMonitor = this.wizard.needsProgressMonitor();
            this.cancelButton.removeSelectionListener(this.cancelListener);
            Display d = this.getShell().getDisplay();
            this.waitCursor = new Cursor(d, 1);
            this.setDisplayCursor(this.waitCursor);
            this.arrowCursor = new Cursor(d, 0);
            this.cancelButton.setCursor(this.arrowCursor);
            savedState = this.saveUIState(needsProgressMonitor && enableCancelButton);
            if (focusControl != null) {
                savedState.put("focusControl", focusControl);
            }

            if (needsProgressMonitor) {
                this.progressMonitorPart.attachToCancelComponent(this.cancelButton);
                this.progressMonitorPart.setVisible(true);
            }
        }

        return savedState;
    }

    protected void backPressed() {
        IWizardPage page = this.currentPage.getPreviousPage();
        if (page != null) {
            this.isMovingToPreviousPage = true;
            this.showPage(page);
        }
    }

    protected void buttonPressed(int buttonId) {
        switch(buttonId) {
            case 14:
                this.backPressed();
                break;
            case 15:
                this.nextPressed();
                break;
            case 16:
                this.finishPressed();
                break;
            case 17:
                this.helpPressed();
        }

    }

    private Point calculatePageSizeDelta(IWizardPage page) {
        Control pageControl = page.getControl();
        if (pageControl == null) {
            return new Point(0, 0);
        } else {
            Point contentSize = pageControl.computeSize(-1, -1, true);
            Rectangle rect = this.pageContainerLayout.getClientArea(this.pageContainer);
            Point containerSize = new Point(rect.width, rect.height);
            return new Point(Math.max(0, contentSize.x - containerSize.x), Math.max(0, contentSize.y - containerSize.y));
        }
    }

    protected void cancelPressed() {
        if (this.activeRunningOperations <= 0L) {
            this.setReturnCode(1);
            this.close();
        } else {
            this.cancelButton.setEnabled(false);
        }

    }

    public boolean close() {
        return this.okToClose() ? this.hardClose() : false;
    }

    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.addHelpListener(new HelpListener() {
            public void helpRequested(HelpEvent event) {
                if (CustomCopyTableWizard.this.currentPage != null) {
                    CustomCopyTableWizard.this.currentPage.performHelp();
                }

            }
        });
    }

    protected void createButtonsForButtonBar(Composite parent) {
        ((GridLayout)parent.getLayout()).makeColumnsEqualWidth = false;
        if (this.wizard.isHelpAvailable()) {
            this.helpButton = this.createButton(parent, 17,BaseMessages.getString( PKG, "CustomCopyTableWizard.Button.Help"), false);
        }

        if (this.wizard.needsPreviousAndNextButtons()) {
            this.createPreviousAndNextButtons(parent);
        }

        this.finishButton = this.createButton(parent, 16, BaseMessages.getString( PKG, "CustomCopyTableWizard.Button.Finish"), true);
        this.cancelButton = this.createCancelButton(parent);
    }

    protected void setButtonLayoutData(Button button) {
        GridData data = new GridData(256);
        int widthHint = this.convertHorizontalDLUsToPixels(61);
        widthHint = Math.min(widthHint, button.getDisplay().getBounds().width / 5);
        Point minSize = button.computeSize(-1, -1, true);
        data.widthHint = Math.max(widthHint, minSize.x);
        button.setLayoutData(data);
    }

    private Button createCancelButton(Composite parent) {
        ++((GridLayout)parent.getLayout()).numColumns;
        Button button = new Button(parent, 8);
        button.setText(BaseMessages.getString( PKG, "CustomCopyTableWizard.Button.Cancel"));
        this.setButtonLayoutData(button);
        button.setFont(parent.getFont());
        button.setData(new Integer(1));
        button.addSelectionListener(this.cancelListener);
        return button;
    }

    protected Button getButton(int id) {
        return id == 1 ? this.cancelButton : super.getButton(id);
    }

    protected Control createContents(Composite parent) {
        this.wizard.addPages();
        Control contents = super.createContents(parent);
        this.createPageControls();
        this.showStartingPage();
        return contents;
    }

    protected Control createDialogArea(Composite parent) {
        Composite composite = (Composite)super.createDialogArea(parent);
        this.pageContainer = this.createPageContainer(composite);
        GridData gd = new GridData(1808);
        gd.widthHint = this.pageWidth;
        gd.heightHint = this.pageHeight;
        this.pageContainer.setLayoutData(gd);
        this.pageContainer.setFont(parent.getFont());
        GridLayout pmlayout = new GridLayout();
        pmlayout.numColumns = 1;
        this.progressMonitorPart = this.createProgressMonitorPart(composite, pmlayout);
        GridData gridData = new GridData(768);
        this.progressMonitorPart.setLayoutData(gridData);
        this.progressMonitorPart.setVisible(false);
        Label separator = new Label(composite, 258);
        separator.setLayoutData(new GridData(768));
        applyDialogFont(this.progressMonitorPart);
        return composite;
    }

    protected ProgressMonitorPart createProgressMonitorPart(Composite composite, GridLayout pmlayout) {
        return new ProgressMonitorPart(composite, pmlayout, -1) {
            String currentTask = null;

            public void setBlocked(IStatus reason) {
                super.setBlocked(reason);
                if (!CustomCopyTableWizard.this.lockedUI) {
                    CustomCopyTableWizard.getBlockedHandler().showBlocked(this.getShell(), this, reason, this.currentTask);
                }

            }

            public void clearBlocked() {
                super.clearBlocked();
                if (!CustomCopyTableWizard.this.lockedUI) {
                    CustomCopyTableWizard.getBlockedHandler().clearBlocked();
                }

            }

            public void beginTask(String name, int totalWork) {
                super.beginTask(name, totalWork);
                this.currentTask = name;
            }

            public void setTaskName(String name) {
                super.setTaskName(name);
                this.currentTask = name;
            }

            public void subTask(String name) {
                super.subTask(name);
                if (this.currentTask == null) {
                    this.currentTask = name;
                }

            }
        };
    }

    private Composite createPageContainer(Composite parent) {
        Composite result = new Composite(parent, 0);
        result.setLayout(this.pageContainerLayout);
        return result;
    }

    private void createPageControls() {
        this.wizard.createPageControls(this.pageContainer);
        IWizardPage[] pages = this.wizard.getPages();

        for(int i = 0; i < pages.length; ++i) {
            IWizardPage page = pages[i];
            if (page.getControl() != null) {
                page.getControl().setVisible(false);
            }
        }

    }

    private Composite createPreviousAndNextButtons(Composite parent) {
        ++((GridLayout)parent.getLayout()).numColumns;
        Composite composite = new Composite(parent, 0);
        GridLayout layout = new GridLayout();
        layout.numColumns = 0;
        layout.marginWidth = 0;
        layout.marginHeight = 0;
        layout.horizontalSpacing = 0;
        layout.verticalSpacing = 0;
        composite.setLayout(layout);
        GridData data = new GridData(68);
        composite.setLayoutData(data);
        composite.setFont(parent.getFont());
        this.backButton = this.createButton(composite, 14, BaseMessages.getString( PKG, "CustomCopyTableWizard.Button.Back"), false);
        this.nextButton = this.createButton(composite, 15, BaseMessages.getString( PKG, "CustomCopyTableWizard.Button.Next"), false);
        return composite;
    }

    private MessageDialog createWizardClosingDialog() {
        MessageDialog result = new MessageDialog(this.getShell(), JFaceResources.getString("WizardClosingDialog.title"), (Image)null, JFaceResources.getString("WizardClosingDialog.message"), 3, new String[]{IDialogConstants.OK_LABEL}, 0);
        return result;
    }

    protected void finishPressed() {
        if (this.wizard.performFinish()) {
            for(int i = 0; i < this.nestedWizards.size() - 1; ++i) {
                ((IWizard)this.nestedWizards.get(i)).performFinish();
            }

            this.setReturnCode(0);
            this.hardClose();
        }

    }

    public IWizardPage getCurrentPage() {
        return this.currentPage;
    }

    protected IProgressMonitor getProgressMonitor() {
        return this.progressMonitorPart;
    }

    protected IWizard getWizard() {
        return this.wizard;
    }

    private boolean hardClose() {
        for(int i = 0; i < this.createdWizards.size(); ++i) {
            IWizard createdWizard = (IWizard)this.createdWizards.get(i);
            createdWizard.dispose();
            createdWizard.setContainer((IWizardContainer)null);
        }

        return super.close();
    }

    protected void helpPressed() {
        if (this.currentPage != null) {
            this.currentPage.performHelp();
        }

    }

    protected void nextPressed() {
        IWizardPage page = this.currentPage.getNextPage();
        if (page != null) {
            this.showPage(page);
        }
    }

    private boolean doPageChanging(IWizardPage targetPage) {
        PageChangingEvent e = new PageChangingEvent(this, this.getCurrentPage(), targetPage);
        this.firePageChanging(e);
        return e.doit;
    }

    private boolean okToClose() {
        if (this.activeRunningOperations > 0L) {
            synchronized(this) {
                this.windowClosingDialog = this.createWizardClosingDialog();
            }

            this.windowClosingDialog.open();
            synchronized(this) {
                this.windowClosingDialog = null;
                return false;
            }
        } else {
            return this.wizard.performCancel();
        }
    }

    private void restoreEnableState(Control w, Map h, String key) {
        if (w != null) {
            Boolean b = (Boolean)h.get(key);
            if (b != null) {
                w.setEnabled(b);
            }
        }

    }

    private void restoreUIState(Map state) {
        this.restoreEnableState(this.backButton, state, "back");
        this.restoreEnableState(this.nextButton, state, "next");
        this.restoreEnableState(this.finishButton, state, "finish");
        this.restoreEnableState(this.cancelButton, state, "cancel");
        this.restoreEnableState(this.helpButton, state, "help");
        Object pageValue = state.get("page");
        if (pageValue != null) {
            ((ControlEnableState)pageValue).restore();
        }

    }

    public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
        Object state = null;
        if (this.activeRunningOperations == 0L) {
            state = this.aboutToStart(fork && cancelable);
        }

        ++this.activeRunningOperations;

        try {
            if (!fork) {
                this.lockedUI = true;
            }

            ModalContext.run(runnable, fork, this.getProgressMonitor(), this.getShell().getDisplay());
            this.lockedUI = false;
        } finally {
            --this.activeRunningOperations;
            if (state != null) {
                this.stopped(state);
            }

        }

    }

    private void saveEnableStateAndSet(Control w, Map h, String key, boolean enabled) {
        if (w != null) {
            h.put(key, w.getEnabled() ? Boolean.TRUE : Boolean.FALSE);
            w.setEnabled(enabled);
        }

    }

    private Map saveUIState(boolean keepCancelEnabled) {
        Map savedState = new HashMap(10);
        this.saveEnableStateAndSet(this.backButton, savedState, "back", false);
        this.saveEnableStateAndSet(this.nextButton, savedState, "next", false);
        this.saveEnableStateAndSet(this.finishButton, savedState, "finish", false);
        this.saveEnableStateAndSet(this.cancelButton, savedState, "cancel", keepCancelEnabled);
        this.saveEnableStateAndSet(this.helpButton, savedState, "help", false);
        if (this.currentPage != null) {
            savedState.put("page", ControlEnableState.disable(this.currentPage.getControl()));
        }

        return savedState;
    }

    private void setDisplayCursor(Cursor c) {
        Shell[] shells = this.getShell().getDisplay().getShells();

        for(int i = 0; i < shells.length; ++i) {
            shells[i].setCursor(c);
        }

    }

    public void setMinimumPageSize(int minWidth, int minHeight) {
        Assert.isTrue(minWidth >= 0 && minHeight >= 0);
        this.pageContainerLayout.minimumWidth = minWidth;
        this.pageContainerLayout.minimumHeight = minHeight;
    }

    public void setMinimumPageSize(Point size) {
        this.setMinimumPageSize(size.x, size.y);
    }

    public void setPageSize(int width, int height) {
        this.pageWidth = width;
        this.pageHeight = height;
    }

    public void setPageSize(Point size) {
        this.setPageSize(size.x, size.y);
    }

    protected void setWizard(IWizard newWizard) {
        this.wizard = newWizard;
        this.wizard.setContainer(this);
        if (!this.createdWizards.contains(this.wizard)) {
            this.createdWizards.add(this.wizard);
            this.nestedWizards.add(this.wizard);
            if (this.pageContainer != null) {
                this.createPageControls();
                this.updateSizeForWizard(this.wizard);
                this.pageContainer.layout(true);
            }
        } else {
            int size = this.nestedWizards.size();
            if (size >= 2 && this.nestedWizards.get(size - 2) == this.wizard) {
                this.nestedWizards.remove(size - 1);
            } else {
                this.nestedWizards.add(this.wizard);
            }
        }

    }

    public void showPage(final IWizardPage page) {
        if (page != null && page != this.currentPage) {
            if (!this.isMovingToPreviousPage) {
                page.setPreviousPage(this.currentPage);
            } else {
                this.isMovingToPreviousPage = false;
            }

            if (this.doPageChanging(page)) {
                if (this.getContents() == null) {
                    this.updateForPage(page);
                } else {
                    BusyIndicator.showWhile(this.getContents().getDisplay(), new Runnable() {
                        public void run() {
                            CustomCopyTableWizard.this.updateForPage(page);
                        }
                    });
                }

            }
        }
    }

    private void updateForPage(IWizardPage page) {
        if (this.wizard != page.getWizard()) {
            this.setWizard(page.getWizard());
        }

        if (page.getControl() == null) {
            page.createControl(this.pageContainer);
            Assert.isNotNull(page.getControl(), JFaceResources.format(JFaceResources.getString("WizardDialog.missingSetControl"), new Object[]{page.getName()}));
            this.updateSize(page);
        }

        IWizardPage oldPage = this.currentPage;
        this.currentPage = page;
        this.currentPage.setVisible(true);
        if (oldPage != null) {
            oldPage.setVisible(false);
        }

        this.update();
    }

    private void showStartingPage() {
        this.currentPage = this.wizard.getStartingPage();
        if (this.currentPage != null) {
            if (this.currentPage.getControl() == null) {
                this.currentPage.createControl(this.pageContainer);
                Assert.isNotNull(this.currentPage.getControl());
            }

            this.currentPage.setVisible(true);
            this.update();
        }
    }

    private void stopped(Object savedState) {
        if (this.getShell() != null) {
            if (this.wizard.needsProgressMonitor()) {
                this.progressMonitorPart.setVisible(false);
                this.progressMonitorPart.removeFromCancelComponent(this.cancelButton);
            }

            Map state = (Map)savedState;
            this.restoreUIState(state);
            this.cancelButton.addSelectionListener(this.cancelListener);
            this.setDisplayCursor((Cursor)null);
            this.cancelButton.setCursor((Cursor)null);
            this.waitCursor.dispose();
            this.waitCursor = null;
            this.arrowCursor.dispose();
            this.arrowCursor = null;
            Control focusControl = (Control)state.get("focusControl");
            if (focusControl != null) {
                focusControl.setFocus();
            }
        }

    }

    protected void update() {
        this.updateWindowTitle();
        this.updateTitleBar();
        this.updateButtons();
        this.firePageChanged(new PageChangedEvent(this, this.getCurrentPage()));
    }

    public void updateButtons() {
        boolean canFlipToNextPage = false;
        boolean canFinish = this.wizard.canFinish();
        if (this.backButton != null) {
            this.backButton.setEnabled(this.currentPage.getPreviousPage() != null);
        }

        if (this.nextButton != null) {
            canFlipToNextPage = this.currentPage.canFlipToNextPage();
            this.nextButton.setEnabled(canFlipToNextPage);
        }

        this.finishButton.setEnabled(canFinish);
        if (canFlipToNextPage && !canFinish) {
            this.getShell().setDefaultButton(this.nextButton);
        } else {
            this.getShell().setDefaultButton(this.finishButton);
        }

    }

    private void updateDescriptionMessage() {
        this.pageDescription = this.currentPage.getDescription();
        this.setMessage(this.pageDescription);
    }

    public void updateMessage() {
        if (this.currentPage != null) {
            this.pageMessage = this.currentPage.getMessage();
            if (this.pageMessage != null && this.currentPage instanceof IMessageProvider) {
                this.pageMessageType = ((IMessageProvider)this.currentPage).getMessageType();
            } else {
                this.pageMessageType = 0;
            }

            if (this.pageMessage == null) {
                this.setMessage(this.pageDescription);
            } else {
                this.setMessage(this.pageMessage, this.pageMessageType);
            }

            this.setErrorMessage(this.currentPage.getErrorMessage());
        }
    }

    private void setShellSize(int width, int height) {
        Rectangle size = this.getShell().getBounds();
        size.height = height;
        size.width = width;
        this.getShell().setBounds(this.getConstrainedShellBounds(size));
    }

    protected void updateSize(IWizardPage page) {
        if (page != null && page.getControl() != null) {
            this.updateSizeForPage(page);
            this.pageContainerLayout.layoutPage(page.getControl());
        }
    }

    public void updateSize() {
        this.updateSize(this.currentPage);
    }

    private void updateSizeForPage(IWizardPage page) {
        Point delta = this.calculatePageSizeDelta(page);
        if (delta.x > 0 || delta.y > 0) {
            Shell shell = this.getShell();
            Point shellSize = shell.getSize();
            this.setShellSize(shellSize.x + delta.x, shellSize.y + delta.y);
            this.constrainShellSize();
        }

    }

    private void updateSizeForWizard(IWizard sizingWizard) {
        Point delta = new Point(0, 0);
        IWizardPage[] pages = sizingWizard.getPages();

        Point shellSize;
        for(int i = 0; i < pages.length; ++i) {
            shellSize = this.calculatePageSizeDelta(pages[i]);
            delta.x = Math.max(delta.x, shellSize.x);
            delta.y = Math.max(delta.y, shellSize.y);
        }

        if (delta.x > 0 || delta.y > 0) {
            Shell shell = this.getShell();
            shellSize = shell.getSize();
            this.setShellSize(shellSize.x + delta.x, shellSize.y + delta.y);
        }

    }

    public void updateTitleBar() {
        String s = null;
        if (this.currentPage != null) {
            s = this.currentPage.getTitle();
        }

        if (s == null) {
            s = "";
        }

        this.setTitle(s);
        if (this.currentPage != null) {
            this.setTitleImage(this.currentPage.getImage());
            this.updateDescriptionMessage();
        }

        this.updateMessage();
    }

    public void updateWindowTitle() {
        if (this.getShell() != null) {
            String title = this.wizard.getWindowTitle();
            if (title == null) {
                title = "";
            }

            this.getShell().setText(title);
        }
    }

    public Object getSelectedPage() {
        return this.getCurrentPage();
    }

    public void addPageChangedListener(IPageChangedListener listener) {
        this.pageChangedListeners.add(listener);
    }

    public void removePageChangedListener(IPageChangedListener listener) {
        this.pageChangedListeners.remove(listener);
    }

    protected void firePageChanged(final PageChangedEvent event) {
        Object[] listeners = this.pageChangedListeners.getListeners();

        for(int i = 0; i < listeners.length; ++i) {
            final IPageChangedListener l = (IPageChangedListener)listeners[i];
            SafeRunnable.run(new SafeRunnable() {
                public void run() {
                    l.pageChanged(event);
                }
            });
        }

    }

    public void addPageChangingListener(IPageChangingListener listener) {
        this.pageChangingListeners.add(listener);
    }

    public void removePageChangingListener(IPageChangingListener listener) {
        this.pageChangingListeners.remove(listener);
    }

    protected void firePageChanging(final PageChangingEvent event) {
        Object[] listeners = this.pageChangingListeners.getListeners();

        for(int i = 0; i < listeners.length; ++i) {
            final IPageChangingListener l = (IPageChangingListener)listeners[i];
            SafeRunnable.run(new SafeRunnable() {
                public void run() {
                    l.handlePageChanging(event);
                }
            });
        }

    }

    protected class PageContainerFillLayout extends Layout {
        public int marginWidth = 5;
        public int marginHeight = 5;
        public int minimumWidth = 0;
        public int minimumHeight = 0;

        public PageContainerFillLayout(int mw, int mh, int minW, int minH) {
            this.marginWidth = mw;
            this.marginHeight = mh;
            this.minimumWidth = minW;
            this.minimumHeight = minH;
        }

        public Point computeSize(Composite composite, int wHint, int hHint, boolean force) {
            if (wHint != -1 && hHint != -1) {
                return new Point(wHint, hHint);
            } else {
                Point result = null;
                Control[] children = composite.getChildren();
                if (children.length > 0) {
                    result = new Point(0, 0);

                    for(int i = 0; i < children.length; ++i) {
                        Point cp = children[i].computeSize(wHint, hHint, force);
                        result.x = Math.max(result.x, cp.x);
                        result.y = Math.max(result.y, cp.y);
                    }

                    result.x += 2 * this.marginWidth;
                    result.y += 2 * this.marginHeight;
                } else {
                    Rectangle rect = composite.getClientArea();
                    result = new Point(rect.width, rect.height);
                }

                result.x = Math.max(result.x, this.minimumWidth);
                result.y = Math.max(result.y, this.minimumHeight);
                if (wHint != -1) {
                    result.x = wHint;
                }

                if (hHint != -1) {
                    result.y = hHint;
                }

                return result;
            }
        }

        public Rectangle getClientArea(Composite c) {
            Rectangle rect = c.getClientArea();
            rect.x += this.marginWidth;
            rect.y += this.marginHeight;
            rect.width -= 2 * this.marginWidth;
            rect.height -= 2 * this.marginHeight;
            return rect;
        }

        public void layout(Composite composite, boolean force) {
            Rectangle rect = this.getClientArea(composite);
            Control[] children = composite.getChildren();

            for(int i = 0; i < children.length; ++i) {
                children[i].setBounds(rect);
            }

        }

        public void layoutPage(Control w) {
            w.setBounds(this.getClientArea(w.getParent()));
        }

        public void setPageLocation(Control w) {
            w.setLocation(this.marginWidth, this.marginHeight);
        }
    }
}
